#!/bin/bash

echo -e -n "\e[34;40m███╗   ███╗██╗   ██╗███████╗\e[0m";
echo -e -n "\e[32;40m      \e[0m";
echo -e "\e[31;40m██████╗ ██╗     ██╗   ██╗███████╗\e[0m";
echo -e -n "\e[34;40m████╗ ████║╚██╗ ██╔╝██╔════╝\e[0m";
echo -e -n "\e[32;40m      \e[0m";
echo -e "\e[31;40m██╔══██╗██║     ██║   ██║██╔════╝\e[0m";
echo -e -n "\e[34;40m██╔████╔██║ ╚████╔╝ ███████╗\e[0m";
echo -e -n "\e[32;40m█████╗\e[0m";
echo -e "\e[31;40m██████╔╝██║     ██║   ██║███████╗\e[0m";
echo -e -n "\e[34;40m██║╚██╔╝██║  ╚██╔╝  ╚════██║\e[0m";
echo -e -n "\e[32;40m╚════╝\e[0m";
echo -e "\e[31;40m██╔═══╝ ██║     ██║   ██║╚════██║\e[0m";
echo -e -n "\e[34;40m██║ ╚═╝ ██║   ██║   ███████║\e[0m";
echo -e -n "\e[32;40m      \e[0m";
echo -e "\e[31;40m██║     ███████╗╚██████╔╝███████║\e[0m";
echo -e -n "\e[34;40m╚═╝     ╚═╝   ╚═╝   ╚══════╝\e[0m";
echo -e -n "\e[32;40m      \e[0m";
echo -e "\e[31;40m╚═╝     ╚══════╝ ╚═════╝ ╚══════╝\e[0m";


i=0
str=""
arr=("|" "/" "-" "\\")
while [ $i -le 20 ]
do
  let index=i%4
  let indexcolor=i%8
  let color=30+indexcolor
  let NUmbER=$i*5
  printf "\e[0;$color;1m[%-40s][%d%%]%c钰深plus脚本加载中\r" "$str" "$NUmbER" "${arr[$index]}"
  sleep 0.1
  let i++
  str+='++'
done
printf "\n"

sed -i 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/selinux/config

systemctl stop firewalld.service
systemctl disable firewalld.service
iptables -F
iptables -X
iptables -Z
service iptables save
echo -e -n "\e[31;40m 必须要先设置主机名且必须相同(y/n): \e[0m"
read pan

sed -i '$a192.168.200.11 mysql1' /etc/hosts
sed -i '$a192.168.200.12 mysql2' /etc/hosts
sed -i '$a192.168.200.13 mycat' /etc/hosts


cd /etc/yum.repos.d/

rm -rvf *

cat >>centos.repo<<OK
[centos]
name=centos
baseurl=file:///opt/centos
gpgcheck=0
enable=1
[gpmall]
name=gpmall
baseurl=file:///opt/gpmall-repo
gpgcheck=0
enable=1
OK

cd

mount -o loop CentOS-7-x86_64-DVD-1511.iso /mnt/
mkdir /opt/centos
cp -rvf /mnt/* /opt/centos
umount /mnt/

cp -rvf /root/gpmall-repo /opt/

yum clean all
yum install  -y  qemu-kvm  openssl libvirt
systemctl restart libvirtd
ln  -sv  /usr/libexec/qemu-kvm /usr/bin/qemu-kvm
yum install net-tools -y
yum install vsftpd -y
systemctl restart vsftpd
systemctl enable vsftpd
sed -i '$ianon_root=/opt/' /etc/vsftpd/vsftpd.conf
mv qemu-ifup-NAT qemu-ifup-NAT.sh
chmod +x qemu-ifup-NAT.sh
qemu-kvm -m 1024 -drive file=/root/cirros-0.3.4-x86_64-disk.img,if=virtio  -net nic,model=virtio  -net tap,script=qemu-ifup-NAT.sh  -nographic

ip addr list

route  -n
